<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<%@ page contentType="text/html; charset=utf-8"%>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>平台管理系统</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
    <link rel="stylesheet" href="/layuiadmin/layui/css/layui.css" media="all">
    <link rel="stylesheet" href="/layuiadmin/style/admin.css" media="all">
    <style type="text/css">
    	.layui-table img {
			width: auto;
			height: auto;
			max-width: 100% !important;
			max-height: 100%;
		}
    </style>
</head>
<body>
<div class="layui-fluid">
    <div class="layui-card">
      <div class="layui-form layui-card-header layuiadmin-card-header-auto">
        <div class="layui-form-item">
          <div class="layui-inline">
            <label class="layui-form-label">标题</label>
            <div class="layui-input-inline">
              <input type="text" name="title" placeholder="请输入" autocomplete="off" class="layui-input">
            </div>
          </div>
          <div class="layui-inline">
            <button class="layui-btn layuiadmin-btn-list" lay-submit lay-filter="LAY-app-contlist-search">
              <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
            </button>
          </div>
          <div class="test-table-reload-btn layui-col-sm-offset10">
            <button class="layui-btn editThis" type="button" style="margin-left: 10px" data-id="">新增</button>
        </div>
        </div>
      </div>

      <div class="layui-card-body">
        <script type="text/html" id="buttonTpl">
          {{#  if(d.hasVideo == 1){ }}
            <button class="layui-btn layui-btn-xs">有视频</button>
          {{#  } else { }}
            <button class="layui-btn layui-btn-primary layui-btn-xs">无视频</button>
          {{#  } }}
        </script> 
        <table class="layui-table" id="table" lay-filter="table"></table> 
        <script type="text/html" id="toolbar">
          <a class="layui-btn layui-btn-normal layui-btn-xs" lay-event="editThis"><i class="layui-icon layui-icon-edit"></i>编辑</a>
          <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delThis"><i class="layui-icon layui-icon-delete"></i>删除</a>
        </script>
      </div>
    </div>
  </div>
<%-- <div class="layui-fluid layadmin-maillist-fluid">
    <div class="layui-row layui-col-space15">
        <div class="layui-col-md12">
            <div class="layui-card">
                <div class="layui-card-body">
                    <table class="layui-table" lay-filter="essay-table" id="essay-table"></table>
                    <script type="text/html" id="table-operate-tool">
                        <div class="layui-btn-container">
                            <button class="layui-btn layui-btn-warm" lay-event="edit">新增商学院</button>
                        </div>
                    </script>
                    <script type="text/html" id="table-operate">
                        <a class="layui-btn layui-btn-sm" lay-event="edit">编辑</a>
                        <a class="layui-btn layui-btn-sm layui-btn-danger" lay-event="delete">删除</a>
                    </script>
                </div>
            </div>
        </div>
    </div>
</div> --%>

<script src="/layuiadmin/layui/layui.js"></script>
<script>
    layui.config({
        base: '/layuiadmin/' //静态资源所在路径
    }).extend({
        index: 'lib/index' //主入口模块
    }).use(['index', 'form', 'table'], function(){
        var $ = layui.$,
            form = layui.form,
            element = layui.element,
            layer = layui.layer,
            table = layui.table,
            admin = layui.admin;
        element.render();
        form.render();

        table.render({
			elem : '.layui-table',
			url : '/news/queryEssayList',
			page:true,
			request: {
				pageName: 'current', //页码的参数名称，默认：page
				limitName: 'size' //每页数据量的参数名，默认：limit
			},
			cols : [[ 
				{field : 'title', title:'标题', minWidth:160},
				{field : 'coverUrl', title:'封面图', minWidth:160, templet : '<div><img src="{{ d.coverUrl }}"></div>'},
				{field : 'content', title : '内容', minWidth:150},
				{field : 'hasVideo', title : '视频', width:150, templet:'#buttonTpl'},
				{field : 'createTime', title : '发布时间', width:160, templet: "<div>{{layui.util.toDateString(d.createTime, 'yyyy-MM-dd HH:mm:ss')}}</div>"},
				{title : '操作', templet:'#toolbar'}
			]],
			skin : "row",
			even: true,
			size:"lg"
		});
        
        var active = {
            editThis: function (id) {
                window.location.href = '/news/essayEdit?id='+id;
            },
            delThis:function (id,url) {
                layer.confirm('确定删除吗？', function(){
                    admin.req({
                        url: url,
                        data: {"id":id},
                        done: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                            }
                        }
                    });
                });
            }
        };
        var type = 'editThis';
        $('.editThis').on('click', function(){
            active[type] && active[type].call(this,$(this).data('id'));
        });
        /* table.on('tool(essay-table)',function(obj){
            var data = obj.data;
            if(obj.event === 'edit'){
                window.location.href = '/news/essayEdit?id='+data.id;
            }else if(obj.event === 'delete'){
                layer.confirm('确定操作吗？', function(){
                    admin.req({
                        url: '/news/deleteEssayById',
                        data: {"id":data.id},
                        done: function(res){
                            if(res.status){
                                layer.msg(res.desc, {icon: 1});
                                setTimeout(function () {
                                    table.reload('essay-table');
                                }, 1000)
                            }else{
                                layer.msg(res.desc,{icon:2});
                            }
                        }
                    });
                });
            }
        }); */
        
      //监听事件
		table.on('tool(table)', function(obj){
			var data = obj.data; //获得当前行数据
			var layEvent = obj.event; //获得 lay-event 对应的值（也可以是表头的 event 参数对应的值）
			var tr = obj.tr; //获得当前行 tr 的DOM对象
			if (layEvent === 'editThis') {// 编辑
				active[layEvent] && active[layEvent].call(this, data.id);
			} else if (layEvent === 'delThis') {// 删除
				var url = "/news/deleteEssayById";
				active[layEvent] && active[layEvent].call(this, data.id, url);
			}
		});
		
		//监听搜索
	    form.on('submit(LAY-app-contlist-search)', function(data){
		    var field = data.field;
		    //执行重载
		    table.reload('table', {
		    	where: field
		   	});
	    });
    });
</script>
</body>
</html>